<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>考勤信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">

</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="form-search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">打卡日期</label>
                            <div class="layui-input-inline">
                                <input type="text" name="startDate" autocomplete="off" class="layui-input date">
                            </div>
                        </div>

                        <button  id="btn-search" lay-submit lay-filter="btn-search-filter" type="button"
                                 class="layui-btn layui-btn-radius layui-btn-normal">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button  id="btn-reset" type="reset" class="layui-btn layui-btn-radius layui-btn-primary">
                            <i class="layui-icon layui-icon-fonts-clear"></i>
                            重置
                        </button>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
            </div>
        </script>

        <table class="layui-hide" id="attendance-table" lay-filter="attendance-table-Filter"></table>


    </div>
</div>
<script th:src="@{lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script>
    function convertStatus(data) {
        if (data.status == '1') {

            return '<a class="layui-btn layui-btn-xs layui-btn-normal">正常</a>';
        } else if (data.status == '0') {
            return '<a class="layui-btn layui-btn-xs layui-btn-danger">异常</a>';
        } else {
            return '无';
        }
    }

</script>


<script type="text/html" id="convertworkTime">
    {{#
    return d.worktime+'小时';
    }}
</script>


<script>
    function refreshTable() {
        $("#form-reset").click();
        $("#btn-search").click();
    }

    layui.use(['form', 'table','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            laydate=layui.laydate,
            table = layui.table;

        laydate.render({
            elem: '.date' //指定元素
        });

        table.render({
            elem: '#attendance-table',
            url: '/empattendance/list',
            toolbar: '#toolbarDemo',
            cols: [
                [
                    {type: "checkbox", width: 50},
                    {field: 'startDate', width: 200, title: '打卡日期', sort: true, align: "center"},
                    {field: 'employee_name', width: 110, title: '员工姓名', align: "center"},
                    {field: 'starttime', width: 220, title: '上班时间', align: "center"},
                    {field: 'endtime', title: '下班时间', width: 220, align: "center"},
                    {field: 'worktime', width: 100, title: '工作时长', templet: '#convertworkTime', align: "center"},
                    {field: 'status', midwidth: 100, title: '状态', templet: convertStatus, align: "center"}
                ]
                ],
            limits: [1, 5, 10, 30, 50, 100],
            limit: 10,
            page: true,
        });

        //监听表单提交
        form.on('submit(btn-search-filter)', function (data) {
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            table.reload('attendance-table', {
                where: { //设定异步数据接口的额外参数，任意设
                    startDate:data.field.startDate
                }
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });
</script>

</body>
</html>